/*
* jlb
*/
package com.jlb.platform.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.platform.entity.PlatformLog;
import com.jlb.platform.service.PlatformLogSV;

/**
 * 平台日志 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/platformLog")
@Slf4j
@Api(value = "平台日志控制器", description = "平台日志控制器")
public class PlatformLogCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private PlatformLogSV platformLogSV;

    /**
     * 查询PlatformLog一个详情信息
     *
     * @param id
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询PlatformLog一个详情信息", notes = "查询PlatformLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id, java.lang.String code) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        PlatformLog platformLog = platformLogSV.load(id, code);
        log.info(JSON.toJSONString(platformLog));
        return BeanRet.create(true, "查询成功", platformLog);
    }


    /**
     * 根据条件id查询PlatformLog一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询PlatformLog一个详情信息", notes = "查询PlatformLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        PlatformLog platformLog = platformLogSV.loadById(id);
        log.info(JSON.toJSONString(platformLog));
        return BeanRet.create(true, "查询成功", platformLog);
    }

    /**
     * 根据条件code查询PlatformLog一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询PlatformLog一个详情信息", notes = "查询PlatformLog一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public BeanRet loadByCode(@PathVariable java.lang.String code) {
        if (code == null) {
            return null;
        }
        PlatformLog platformLog = platformLogSV.loadByCode(code);
        log.info(JSON.toJSONString(platformLog));
        return BeanRet.create(true, "查询成功", platformLog);
    }


    /**
     * 查询PlatformLog信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询PlatformLog信息集合", notes = "查询PlatformLog信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query")
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore PlatformLog platformLog, Integer curPage, Integer pageSize) {
        Page<PlatformLog> page = new Page<PlatformLog>(pageSize, curPage);
        List<PlatformLog> platformLogs = platformLogSV.list(platformLog, page.genRowStart(), page.getPageSize());
        page.setVoList(platformLogs);
        int total = platformLogSV.count(platformLog);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询PlatformLog信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询PlatformLog信息集合", notes = "查询PlatformLog信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id, java.lang.String code, Integer curPage, Integer pageSize) {
        Page<PlatformLog> page = new Page<PlatformLog>(pageSize, curPage);
        List<PlatformLog> platformLogs = platformLogSV.list(id, code, page.genRowStart(), page.getPageSize());
        page.setVoList(platformLogs);
        int total = platformLogSV.count(id, code);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计PlatformLog信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计PlatformLog信息数量根据主键", notes = " 统计PlatformLog信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String code) {
        return platformLogSV.count(id, code);
    }

    /**
     * 统计PlatformLog信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计PlatformLog信息数量", notes = "统计PlatformLog信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "account", value = "账户", paramType = "query"),
            @ApiImplicitParam(name = "log", value = "日志", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore PlatformLog platformLog) {
        if (platformLog == null) {
            return platformLogSV.count(new HashMap());
        } else {
            return platformLogSV.count(platformLog);
        }
    }


    /**
     * 创建PlatformLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建PlatformLog", notes = "创建PlatformLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "账户", paramType = "query"),
            @ApiImplicitParam(name = "log", value = "日志", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore PlatformLog platformLog) {
        platformLogSV.save(platformLog);
        return BeanRet.create(true, "创建成功", platformLog);
    }


    /**
     * 修改PlatformLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改PlatformLog", notes = "修改PlatformLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "account", value = "账户", paramType = "query"),
            @ApiImplicitParam(name = "log", value = "日志", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore PlatformLog platformLog) {
        platformLogSV.modify(platformLog);
        return BeanRet.create(true, "修改成功", platformLog);
    }

    /**
     * 删除PlatformLog
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除PlatformLog", notes = "删除PlatformLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String code) {
        platformLogSV.delete(id, code);
        return BeanRet.create(true, "删除PlatformLog成功");
    }

}
